Imports MIMS.WRS.Entities
Imports MIMS.WRS.Business
Imports System.Text
Imports MyFramework

Public Class MUKDetail
    Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents txtCon As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtSupp As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtOrderNo As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtReq As System.Web.UI.WebControls.TextBox
    Protected WithEvents ddlType As System.Web.UI.WebControls.DropDownList    
    Protected WithEvents txtVessel As System.Web.UI.WebControls.TextBox
    Protected WithEvents chkDocRec As System.Web.UI.WebControls.CheckBox
    Protected WithEvents ddlBulk As System.Web.UI.WebControls.DropDownList
    Protected WithEvents ddlSize As System.Web.UI.WebControls.DropDownList
    Protected WithEvents ddlPayment As System.Web.UI.WebControls.DropDownList
    Protected WithEvents ddlPack As System.Web.UI.WebControls.DropDownList
    Protected WithEvents ddlSL As System.Web.UI.WebControls.DropDownList    
    Protected WithEvents txtAccNo As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtCustomer As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtFinalDestination As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtArrivalPort As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtDescription As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtContainerNo As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtPISC As System.Web.UI.WebControls.TextBox    
    Protected WithEvents btnSubmit As System.Web.UI.WebControls.Button
    Protected WithEvents txtWeek As System.Web.UI.WebControls.TextBox
    Protected WithEvents CompareValidator2 As System.Web.UI.WebControls.CompareValidator
    Protected WithEvents ValidationSummary1 As System.Web.UI.WebControls.ValidationSummary
    Protected WithEvents Comparevalidator3 As System.Web.UI.WebControls.CompareValidator
    Protected WithEvents Comparevalidator4 As System.Web.UI.WebControls.CompareValidator
    Protected WithEvents Comparevalidator5 As System.Web.UI.WebControls.CompareValidator
    Protected WithEvents ddlPayAuth As System.Web.UI.WebControls.DropDownList    
    Protected WithEvents lblMessage As System.Web.UI.WebControls.Label
    Protected WithEvents RequiredFieldValidator2 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents RequiredFieldValidator3 As System.Web.UI.WebControls.RequiredFieldValidator    
    Protected WithEvents txtInvValue As System.Web.UI.WebControls.TextBox    
    Protected WithEvents CompareValidator6 As System.Web.UI.WebControls.CompareValidator
    Protected WithEvents Requiredfieldvalidator4 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents Requiredfieldvalidator5 As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents ddlPrimary As System.Web.UI.WebControls.DropDownList
    Protected WithEvents lblSuppOrderNo As System.Web.UI.WebControls.Label
    Protected WithEvents ltrNavigator As System.Web.UI.WebControls.Literal
    Protected WithEvents txtSInvoiced As System.Web.UI.WebControls.TextBox
    Protected WithEvents Comparevalidator7 As System.Web.UI.WebControls.CompareValidator
    Protected WithEvents chkOnHold As System.Web.UI.WebControls.CheckBox
    Protected WithEvents txtCustPONo As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtCatalogue As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtSLCode As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtSLUrl As System.Web.UI.WebControls.TextBox

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Protected WithEvents calOrderDate As DateTimePicker
    Protected WithEvents calPOInOpera As DateTimePicker
    Protected WithEvents calFactoryETD As DateTimePicker
    Protected WithEvents calShippedDate As DateTimePicker
    Protected WithEvents calETADate As DateTimePicker
    Protected WithEvents calConDel As DateTimePicker
    Protected WithEvents calSInvoicedPd As DateTimePicker
    Protected WithEvents calPPayDate As DateTimePicker
    Protected WithEvents calCompletedDate As DateTimePicker


    Private ssr As ShippingStatusReport = Nothing

    Private ReadOnly Property IsAddNew() As Boolean
        Get
            If RequestContext.ShippingStatusReportID <= 0 Then
                Return True
            Else
                Return False
            End If
        End Get
    End Property

    Private ReadOnly Property SupplierOrderNumbers() As ArrayList
        Get
            If (Session("ChainOfID") Is Nothing _
                OrElse Convert.ToString(Session("ChainOfID")) <> RequestContext.ChainOfID) Then
                Session("ChainOfID") = RequestContext.ChainOfID
                ' refresh the Supplier Order numbers list
                Dim i As Int32
                Dim alSON As ArrayList = New ArrayList

                For i = 0 To RequestContext.SelectedIDs.Count - 2
                    Dim id As Int32 = Convert.ToInt32(RequestContext.SelectedIDs(i))
                    Try
                        Dim obj As ShippingStatusReport = ShippingStatusReportService.GetShippingStatusReport(id)
                        alSON.Add(obj.SuppOrderNo)
                    Catch ex As Exception
                        alSON.Add("Failed:" + id.ToString())
                    End Try
                Next

                Session("SON") = alSON                
            End If

            Return CType(Session("SON"), ArrayList)
        End Get
    End Property

    Private Sub BuildNavigator()
        Dim sb As StringBuilder = New StringBuilder

        If RequestContext.ChainOfID.Length > 0 Then
            Dim i As Int32
            ' RequestContext.SelectedIDs.Count always >= 2
            For i = 0 To RequestContext.SelectedIDs.Count - 2
                Dim id As String = Convert.ToString(RequestContext.SelectedIDs(i))
                Dim suppOrderNo As String = Convert.ToString(SupplierOrderNumbers(i))

                If (id.Equals(RequestContext.ShippingStatusReportID.ToString())) Then
                    sb.AppendFormat("<span class=""Selected"">[{0}]</span>", suppOrderNo)
                Else
                    sb.AppendFormat("<a href=""{0}"">[{1}]</a>", _
                        ResolveUrl(UrlBuilder.GetMUKDetailUrl(Integer.Parse(id), RequestContext.ChainOfID, False, RequestContext.Changed)), suppOrderNo)
                End If

                sb.Append("&nbsp;&nbsp;")
            Next
        Else
            sb.Append("<span class=""Selected"">[NEW RECORD]</span>")
        End If

        ltrNavigator.Text = sb.ToString()
    End Sub

    Private Function BuildObject() As Boolean
        If IsAddNew Then
            ssr = New ShippingStatusReport
        Else
            Try
                ssr = ShippingStatusReportService.GetShippingStatusReport(RequestContext.ShippingStatusReportID)

                If ssr Is Nothing Then
                    Throw New Exception
                End If
            Catch ex As Exception
                Me.lblMessage.Text = "Failed to load order. Order not found or has been deleted"
                Return False
                'Throw New Exception("Failed to load shipping report data", ex)
            End Try
        End If

        Return True
    End Function

    Public Shared Function GetWeek(ByVal inDate As Date) As Int32
        Dim wk As Int32 = DatePart(DateInterval.WeekOfYear, inDate.AddDays(-1))

        If wk > 52 Then
            wk = 52
        End If

        Return wk
    End Function


    'Private Function GetDate(ByVal inDate As DateTime) As DateTime
    '    If (inDate.Equals(DateTime.MinValue)) Then
    '        Return Nulls.NullDate
    '    Else
    '        Return inDate
    '    End If
    'End Function

    Private Sub UpdateData(ByVal bSave As Boolean)
        If (bSave) Then
            ssr.AccNo = txtAccNo.Text.Trim()
            ssr.ArrivalPort = txtArrivalPort.Text.Trim()
            ssr.BulkType = ddlBulk.SelectedItem.Value
            'Try
            '    ssr.BulkOrderNo = Integer.Parse(txtBKOrderNo.Text.Trim())
            'Catch
            '    ssr.BulkOrderNo = Null.NullInteger
            'End Try

            ssr.CompletedDate = calCompletedDate.SelectedValue
            ssr.ContainerNo = txtContainerNo.Text.Trim()
            ssr.ContainerSize = ddlSize.SelectedItem.Value
            ssr.ContainerDeliveried = calConDel.SelectedValue
            ssr.CustomerOrLocation = txtCustomer.Text.Trim()
            ssr.Description = txtDescription.Text.Trim()
            ssr.DocReceived = chkDocRec.Checked
            ssr.ETA = calETADate.SelectedValue
            ssr.FactoryETD = calFactoryETD.SelectedValue
            ssr.FinalDestination = txtFinalDestination.Text.Trim()
            ssr.IsPrimary = ddlPrimary.SelectedItem.Value
            ssr.LP = ddlPack.SelectedItem.Value
            ssr.ModifiedDate = DateTime.Now
            ssr.OrderDate = calOrderDate.SelectedValue

            If (Security.IsAdmin) Then
                ssr.PayAuth = ddlPayAuth.SelectedItem.Value
            End If

            ssr.Payment = ddlPayment.SelectedItem.Value
            ssr.PI = txtPISC.Text.Trim()

            Try
                If txtCon.Text.Trim().Length > 0 Then ssr.PONo_Consolidation = Integer.Parse(txtCon.Text.Trim())
            Catch
                ssr.PONo_Consolidation = Nulls.NullInteger
            End Try

            Try
                If txtOrderNo.Text.Trim().Length > 0 Then ssr.PONo_Number = Integer.Parse(txtOrderNo.Text.Trim())
            Catch
                ssr.PONo_Number = Nulls.NullInteger
            End Try

            Try
                If txtSupp.Text.Trim().Length > 0 Then ssr.PONo_Supplier = Integer.Parse(txtSupp.Text.Trim())
            Catch
                ssr.PONo_Supplier = Nulls.NullInteger
            End Try

            ssr.PONo_Type = ddlType.SelectedItem.Value
            Try
                If txtReq.Text.Trim().Length > 0 Then ssr.REQ = Integer.Parse(txtReq.Text.Trim())
            Catch
                ssr.REQ = Nulls.NullInteger
            End Try

            ssr.ShippingDate = calShippedDate.SelectedValue
            ssr.ShippingLine = ddlSL.SelectedItem.Value
            ssr.Vessel = txtVessel.Text.Trim()

            If Not ssr.ETA = Nulls.NullDate Then
                ssr.Week = GetWeek(ssr.ETA)
            End If

            ssr.POInOpera = calPOInOpera.SelectedValue
            Try
                ssr.InvValue = Convert.ToDecimal(txtInvValue.Text)
            Catch
                ssr.InvValue = Nulls.NullDecimal
            End Try

            ssr.PayDate = calPPayDate.SelectedValue

            ssr.SuppOrderNo = String.Format("{0}{1}", ssr.PONo_Supplier.ToString().PadLeft(3, "0"c), ssr.PONo_Number.ToString().PadLeft(3, "0"c))

            ssr.PONo_Office = Config.PONOOffice
            Try
                If txtSInvoiced.Text.Trim().Length > 0 Then ssr.SInvoiced = Convert.ToInt32(txtSInvoiced.Text.Trim())
            Catch
                ssr.SInvoiced = Nulls.NullInteger
            End Try

            ssr.OnHold = chkOnHold.Checked

            ssr.OfficeID = RequestContext.CurrentUser.ActiveOfficeID

            ssr.CustPONo = txtCustPONo.Text

            'ssr.BulkOrderOfficeID = Integer.Parse(ddlOffices.SelectedItem.Value)
            ssr.SInvoicedPd = calSInvoicedPd.SelectedValue
            ssr.Catalogue = txtCatalogue.Text
            ssr.ShippingLineID = Integer.Parse(ddlSL.SelectedItem.Value)
            ssr.ShippingLineCode = txtSLCode.Text.Trim()
            ssr.ShippingLineUrl = txtSLUrl.Text
        Else
            Me.txtAccNo.Text = ssr.AccNo
            Me.txtArrivalPort.Text = ssr.ArrivalPort

            'If (ssr.BulkOrderNo <> Null.NullInteger) Then Me.txtBKOrderNo.Text = ssr.BulkOrderNo.ToString().PadLeft(6, "0"c)

            If (ssr.CompletedDate <> Nulls.NullDate) Then calCompletedDate.SelectedValue = ssr.CompletedDate
            
            If (ssr.PONo_Consolidation <> Nulls.NullInteger) Then Me.txtCon.Text = ssr.PONo_Consolidation.ToString()

            Me.txtContainerNo.Text = ssr.ContainerNo
            Me.txtCustomer.Text = ssr.CustomerOrLocation
            Me.txtDescription.Text = ssr.Description

            If (ssr.ETA <> Nulls.NullDate) Then calETADate.SelectedValue = ssr.ETA

            If (ssr.FactoryETD <> Nulls.NullDate) Then calFactoryETD.SelectedValue = ssr.FactoryETD

            Me.txtFinalDestination.Text = ssr.FinalDestination

            If (ssr.OrderDate <> Nulls.NullDate) Then calOrderDate.SelectedValue = ssr.OrderDate

            If (ssr.PONo_Number <> Nulls.NullInteger) Then Me.txtOrderNo.Text = ssr.PONo_Number.ToString()

            Me.txtPISC.Text = ssr.PI

            If (ssr.REQ <> Nulls.NullInteger) Then Me.txtReq.Text = ssr.REQ.ToString()

            If (ssr.ShippingDate <> Nulls.NullDate) Then calShippedDate.SelectedValue = ssr.ShippingDate

            If (ssr.ContainerDeliveried <> Nulls.NullDate) Then calConDel.SelectedValue = ssr.ContainerDeliveried

            If (ssr.PONo_Supplier <> Nulls.NullInteger) Then Me.txtSupp.Text = ssr.PONo_Supplier.ToString()

            Me.txtVessel.Text = ssr.Vessel

            Try
                Me.ddlSL.SelectedIndex = Me.ddlSL.Items.IndexOf(Me.ddlSL.Items.FindByValue(ssr.ShippingLine))
            Catch ex As Exception
            End Try

            Try
                Me.ddlPayment.SelectedIndex = Me.ddlPayment.Items.IndexOf(Me.ddlPayment.Items.FindByValue(ssr.Payment))
            Catch ex As Exception
            End Try

            Try
                Me.ddlBulk.SelectedIndex = Me.ddlBulk.Items.IndexOf(Me.ddlBulk.Items.FindByValue(ssr.BulkType))
            Catch ex As Exception
            End Try

            Try
                Me.ddlPack.SelectedIndex = Me.ddlPack.Items.IndexOf(Me.ddlPack.Items.FindByValue(ssr.LP))
            Catch ex As Exception
            End Try

            Try
                Me.ddlSize.SelectedIndex = Me.ddlSize.Items.IndexOf(Me.ddlSize.Items.FindByValue(ssr.ContainerSize))
            Catch ex As Exception
            End Try

            Try
                Me.ddlType.SelectedIndex = Me.ddlType.Items.IndexOf(Me.ddlType.Items.FindByValue(ssr.PONo_Type))
            Catch ex As Exception
            End Try

            If (Security.IsAdmin) Then
                Try
                    Me.ddlPayAuth.SelectedIndex = Me.ddlPayAuth.Items.IndexOf(Me.ddlPayAuth.Items.FindByValue(ssr.PayAuth))
                Catch ex As Exception
                End Try
            End If

            ddlPrimary.SelectedIndex = ddlPrimary.Items.IndexOf(ddlPrimary.Items.FindByValue(ssr.IsPrimary))

            chkDocRec.Checked = ssr.DocReceived

            If (ssr.Week <> Nulls.NullInteger) Then Me.txtWeek.Text = ssr.Week.ToString()

            If (ssr.POInOpera <> Nulls.NullDate) Then calPOInOpera.SelectedValue = ssr.POInOpera

            If (ssr.InvValue <> Nulls.NullDecimal) Then Me.txtInvValue.Text = ssr.InvValue.ToString(Config.DecimalFormat)

            If (ssr.PayDate <> Nulls.NullDate) Then calPPayDate.SelectedValue = ssr.PayDate

            Me.lblSuppOrderNo.Text = ssr.SuppOrderNo

            If (ssr.SInvoiced <> Nulls.NullDecimal) Then Me.txtSInvoiced.Text = ssr.SInvoiced.ToString(Config.DecimalFormat)

            chkOnHold.Checked = ssr.OnHold

            txtCustPONo.Text = ssr.CustPONo

            'Try
            '    Me.ddlOffices.SelectedIndex = Me.ddlOffices.Items.IndexOf(Me.ddlOffices.Items.FindByValue(ssr.BulkOrderOfficeID.ToString()))
            'Catch ex As Exception

            'End Try
            If (ssr.SInvoicedPd <> Nulls.NullDate) Then calSInvoicedPd.SelectedValue = ssr.SInvoicedPd
            txtCatalogue.Text = ssr.Catalogue
            ddlSL.SelectedIndex = ddlSL.Items.IndexOf(ddlSL.Items.FindByValue(ssr.ShippingLineID.ToString))
        End If
    End Sub

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        

        If Not IsPostBack Then
            Response.Write("<div id='pleaseWait'>Please wait...</div>")
            Response.Flush()

            ' refresh parent if requested
            If (RequestContext.RefreshParent) Then
                Page.RegisterStartupScript("windowClose", "<script language='javascript'>windowCloseAndRefresh();</script>")
                'by pass all the remain process 
                'render only closing script
                Exit Sub
            End If

            BuildNavigator()

            ' get list of available office for this user
            ' check security
            Dim col As OfficeCollection = OfficeService.GetOffices(RequestContext.CurrentUser.US_ID_PK)

            If (col.Count = 0) Then                
                Throw New Exception("This user doesn't belong to any offices. Contact admin for more details.")                
            End If

            'Me.ddlOffices.DataSource = OfficeService.GetOffices(OfficeColumns.OfficeID, OrderDirection.ASC)
            'Me.ddlOffices.DataTextField = OfficeColumns.OfficeCode.ToString()
            'Me.ddlOffices.DataValueField = OfficeColumns.OfficeID.ToString()
            'Me.ddlOffices.DataBind()

            'Me.ddlOffices.Items.Insert(0, New ListItem("", "-1"))
            ddlSL.DataSource = ShippingLineService.GetShippingLines(ShippingLineColumns.Abbr, OrderDirection.ASC)
            ddlSL.DataTextField = ShippingLineColumns.Abbr.ToString()
            ddlSL.DataValueField = ShippingLineColumns.ID.ToString()
            ddlSL.DataBind()
            ddlSL.Items.Insert(0, New ListItem("", Nulls.NullInteger.ToString()))

            If (IsAddNew) Then
                ' initalize value
                Me.btnSubmit.Text = "Create new order"

                '                Me.ddlOffices.SelectedIndex = Me.ddlOffices.Items.IndexOf(Me.ddlOffices.Items.FindByValue(RequestContext.CurrentUser.ActiveOfficeID.ToString()))
            Else
                Me.btnSubmit.Text = "Update order"

                If BuildObject() Then
                    Dim found As Boolean = False

                    For Each office As office In col
                        If ssr.OfficeID = office.OfficeID Then
                            found = True
                            Exit For
                        End If
                    Next

                    If Not found Then
                        Logger.Info(String.Format("Security WARNING: user {0} had attempt to invalid access order {1}", RequestContext.CurrentUser.US_ID_PK, RequestContext.ShippingStatusReportID))
                        Throw New Exception("Your request order doesn't belong to this user. Contact admin for more details.")
                    End If

                    UpdateData(False)
                End If
            End If
        End If
    End Sub

    Private Sub NavigateNext()
        Dim id As String = RequestContext.ShippingStatusReportID.ToString()
        Dim idx As Integer = RequestContext.SelectedIDs.IndexOf(id)

        ' the last item in RequestContext.SelectedIDs is a empty one
        ' by pass that item (Count - 2)
        If (idx < RequestContext.SelectedIDs.Count - 2) Then
            Response.Redirect(ResolveUrl(UrlBuilder.GetMUKDetailUrl(Convert.ToInt32(RequestContext.SelectedIDs(idx + 1)), RequestContext.ChainOfID, False, True)))
        Else
            Response.Redirect(ResolveUrl(UrlBuilder.GetMUKDetailUrl(Convert.ToInt32(id), RequestContext.ChainOfID, True, True)))
        End If
    End Sub

    Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        If Page.IsValid Then

            'If ddlBulk.SelectedIndex > 0 AndAlso txtBKOrderNo.Text.Trim.Length = 0 Then
            '    Me.lblMessage.Text = String.Format("You have selected '{0}' bulk type. Please input Bulk Order number", Me.ddlBulk.SelectedItem.Text)
            '    Return
            'End If

            If BuildObject() = False Then
                Return
            End If

            Dim oldETDDate As DateTime = ssr.FactoryETD
            Dim oldETADate As DateTime = ssr.ETA
            Dim oldShippedDate As DateTime = ssr.ShippingDate

            UpdateData(True)

            Dim saveCompleted As Boolean = False

            Try
                If IsAddNew Then
                    ShippingStatusReportService.CreateShippingStatusReport(ssr)
                Else
                    ShippingStatusReportService.UpdateShippingStatusReport(ssr)
                End If
                saveCompleted = True

            Catch ex As MyFramework.BusinessException
                If (TypeOf (ex.InnerException) Is MyFramework.DataAccessException) Then
                    If (ex.InnerException.InnerException.Message.IndexOf("IX_ShippingStatusReport") > -1) Then
                        Me.lblMessage.Text = "The supplier number and order number has already existed. Please enter another."
                    Else
                        Me.lblMessage.Text = ex.InnerException.InnerException.Message
                    End If
                Else
                    Me.lblMessage.Text = ex.Message
                End If
            Catch ex As Exception
                Me.lblMessage.Text = ex.Message
            End Try

            If saveCompleted Then
                If IsAddNew Then
                    ' redirect to itself to add another and refresh the parent page
                    Response.Redirect(ResolveUrl(UrlBuilder.GetMUKDetailUrl(0, "", False, True)))
                Else
                    ' check for ETA or ETD has changed since its last first entry
                    Dim mail As FactoryDateChangedMail = New FactoryDateChangedMail
                    mail.POMUKNumber = ssr.SuppOrderNo

                    Try
                        If (oldETADate <> Nulls.NullDate AndAlso oldETADate.Equals(ssr.ETA) = False) Then
                            mail.OldDate = oldETADate.ToShortDateString()
                            mail.NewDate = ssr.ETA.ToShortDateString()
                            mail.DateType = "ETA"
                            mail.Send()
                        End If

                    Catch ex As Exception
                        Logger.Error("Failed to send FactoryDateChangedEmail", ex)
                    End Try

                    Try
                        If (oldETDDate <> Nulls.NullDate AndAlso oldETDDate.Equals(ssr.FactoryETD) = False) Then
                            mail.OldDate = oldETDDate.ToShortDateString()
                            mail.NewDate = ssr.FactoryETD.ToShortDateString()
                            mail.DateType = "Factory ETD"
                            mail.Send()
                        End If
                    Catch ex As Exception
                        Logger.Error("Failed to send FactoryDateChangedEmail", ex)
                    End Try

                    Try
                        If (oldShippedDate <> Nulls.NullDate AndAlso oldShippedDate.Equals(ssr.ShippingDate) = False) Then
                            Dim shippedDateChangedEmailObj As ShippedDateChangedMail = New ShippedDateChangedMail
                            shippedDateChangedEmailObj.POMUKNumber = ssr.SuppOrderNo
                            shippedDateChangedEmailObj.Send()
                        End If
                    Catch ex As Exception
                        Logger.Error("Failed to send ShippedDateChangedEmail", ex)
                    End Try

                    NavigateNext()
                End If
            End If
        End If
    End Sub
End Class
